<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <!-- <title>登录 - 我是一阵风直播</title> -->
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
  	<style>
        .title{
            margin:2.5rem 0rem 2rem 0rem;
        }
        .login-sub {
            margin-top: 3rem;
        }
        .login-third {
            margin-top: 3rem;
        }
        .login-con{
            margin-top:2.5rem;
        }
        .aui-bar-btn-item{line-height:2rem;}
  	</style>
</head>
<body>
    <header class="aui-bar aui-bar-nav" id="aui-header">
        <!-- <div class="aui-title">登录 - 我是一阵风主播端</div> -->
    </header>
    <section class="aui-content login-con">
        <div class="aui-bar aui-bar-btn aui-bar-btn-round" style="width:80%;margin-bottom:1rem;">
            <div class="aui-bar-btn-item" tapmode onclick="openFrm('login_pass_frm')">账号密码登录</div>
            <div class="aui-bar-btn-item aui-active">手机号登录</div>
        </div>
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label aui-border-r color-orange">
                        手机号 <small class="aui-margin-l-5 aui-text-warning">+86</small>
                    </div>
                    <div class="aui-list-item-input aui-padded-l-10">
                        <input type="number" pattern="[0-9]*" placeholder="输入手机号" id="mobile">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-input" style="width: auto;">
                        <input type="number" pattern="^1[345678][0-9]{9}$" placeholder="输入短信验证码" id="code">
                    </div>
                    <div class="aui-list-item-label aui-margin-r-15" style="width: 6rem;">
                        <div id="GetCode" class="aui-btn aui-btn-info" style="width: 6rem;">获取验证码</div>
                    </div>
                </div>
            </li>
        </ul>
    </section>
    <section class="aui-content-padded login-sub">
        <div class="aui-btn aui-btn-block aui-btn-info" tapmode onclick="fnLogin()">登录</div>
    </section>
    <section class="aui-content-padded login-third">
        <p class="aui-font-size-12 aui-text-center aui-margin-b-15">第三方账号登录</p>
        <div class="aui-grid" style="background: none;">
            <div class="aui-row">
                <div class="aui-col-xs-4">
                    <i class="aui-iconfont aui-icon-qq"></i>
                </div>
                <div class="aui-col-xs-4">
                    <i class="aui-iconfont aui-icon-wechat"></i>
                </div>
                <div class="aui-col-xs-4">
                    <i class="aui-iconfont aui-icon-alipay"></i>
                </div>
            </div>
        </div>
    </section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
    apiready = function(){
        fixStatusBar();

        api.parseTapmode();
    };
    /**
    *手机号登录
    */
    function fnLogin(){
        openFrm('home_frm');
    }
    $api.addEvt($api.dom('#GetCode'), 'click',function(){

        var mobile = $api.val($api.byId('mobile'));
         var type ='public_login';
          if(!$api.trim(mobile)){
             api.toast({
               msg: '请输入手机号',
               duration: 1000,
               location: 'middle'
           });
                     return;
                }

      var timestamp = parseInt(new Date().getTime()/1000);
            md5(timestamp,function(ret){
              if(ret.status){
               var appid= 'live001';
               var scp='XnQp2uUaQY0f8Ln';
               var key0=appid+ret.value.toLowerCase()+scp;
               md5(key0,function(ret){
                 if(ret.status){
                   api.ajax({
                     url: "https://www.qiersan.com/base/sms/send",
                     method: 'post',
                     headers: {
                       'appid':'live001',
                       'time':timestamp,
                       'key':ret.value.toLowerCase()
                               },
                     data: {
                       'values':{
                         "type":'public_login',
                         "phone":mobile

                       }
                     }
                   },function(ret,err){
                     if (ret.code==1) {
                       get_auth_code('#GetCode',Date.now());
                        //console.log($api.jsonToStr(ret));
                        api.toast({
                          msg: '发送成功',
                          duration: 1000,
                          location: 'middle'
                        });
                     }else{
                       console.log($api.jsonToStr(ret));
                     }


                   });
                 }
               });
              }
            });


        });

        function get_auth_code(el,getCodeTime){
            if(Date.now()-getCodeTime<60000){
                $api.html($api.dom(el),'重新获取('+Math.ceil( (getCodeTime/1+60000-Date.now())/1000 )+'s)');
                $api.css($api.dom(el),'pointer-events:none;color:#fff;background: #ccc;');
                setTimeout(function(){get_auth_code(el,getCodeTime)},1000);
            }else{
                $api.html($api.dom(el),'获取验证码');
                $api.css($api.dom(el),'pointer-events:auto;color:#fff;background: #F37668;');

            }
        };

        /**
        *账号密码登录
        */
        function fnLogin(){
          var mobile = $api.val($api.byId('mobile'));
           var code = $api.val($api.byId('code'));
           if (!$api.trim(mobile)) {
               api.toast({
             msg: '请输入手机号',
             duration: 1000,
             location: 'middle'
         });
         return;
       }
           if (!$api.trim(code)) {
               api.toast({
             msg: '请输入验证码',
             duration: 1000,
             location: 'middle'
         });
         return;
       }
       /*** 加载动画 ***/
               api.showProgress({
                   title : ' ',
                   text : '玩命加载中...',
                   modal : true
               });

               var timestamp = parseInt(new Date().getTime()/1000);

               md5(timestamp,function(ret){
                 if(ret.status){
                  var appid= 'live001';
                  var scp='XnQp2uUaQY0f8Ln';
                  var key0=appid+ret.value.toLowerCase()+scp;
                  md5(key0,function(ret){
                    if(ret.status){
                      api.ajax({
                        url: "https://www.qiersan.com/login/user/login",
                        method: 'post',
                        headers: {
                          'appid':'live001',
                          'time':timestamp,
                          'key':ret.value.toLowerCase()
                                  },
                        data: {
                          'values':{
                            "login_type":'phone',
                            "phone":mobile,
                            "code":code
                          }
                        }
                      },function(ret,err){
                        api.hideProgress();

                        //console.log($api.jsonToStr(ret));

                        if(ret.code==1){
                          api.toast({
                  　　　　　　msg:'登录成功',
                  　　　　　　duration: '1200',
                  　　　　　　localtion: 'middle'
                　　　　　　});
                          $api.setStorage('isLogin', 1);
                          $api.setStorage('token', ret.data.token);

                          var token = ret.data.token;

                          md5(timestamp,function(ret){
                            if(ret.status){
                             var appid= 'live001';
                             var scp='XnQp2uUaQY0f8Ln';
                             var key0=appid+ret.value.toLowerCase()+scp;
                             md5(key0,function(ret){
                               if(ret.status){
                                 api.ajax({
                                   url: "https://www.qiersan.com/user/user/find",
                                   method: 'post',
                                   headers: {
                                     'appid':'live001',
                                     'time':timestamp,
                                     'key':ret.value.toLowerCase()
                                             },
                                   data: {
                                     'values':{
                                       "token":token
                                     }
                                   }
                                 },function(ret,err){
                                   //console.log($api.jsonToStr(ret.data.true_name));
                                   if(ret.code==1){
                                     $api.setStorage('phone', ret.data.phone);
                                     $api.setStorage('true_name', ret.data.true_name);
                                     $api.setStorage('headimg_url', ret.data.headimg_url);
                                     $api.setStorage('userid', ret.data.user_id);
                                   }
                                   //console.log($api.jsonToStr(ret));
                                   //console.log($api.jsonToStr(ret));
                                   $api.post(baseUrl+'live/live/my_video',{
                                   body: 'String',values:{user_id:ret.data.user_id}
                                 },function(ret){
                                     var newret = JSON.parse(ret);
                                   if(newret.code==1){
                                     $api.setStorage('creattime', newret.data.created_at);
                                     $api.setStorage('title', newret.data.title);
                                     $api.setStorage('rid', newret.data.rid);
                                      $api.setStorage('pushurl', newret.data.pushurl);
                                      $api.setStorage('live_cover', newret.data.live_cover);
                                   }
                                 },'text');

                                 });
                               }
                             });
                            }
                          });
                          setTimeout(function(){
                            window.location.href="video_frm.html";
                          },1000);
                        }else {
                          api.toast({
                  　　　　　　msg:'登录失败',
                  　　　　　　duration: '1200',
                  　　　　　　localtion: 'middle'
                　　　　　　});
                        }
                      });
                    }
                  });
                 }
               });

        }
        function md5(string,callback){
           var signature = api.require('signature');
          signature.md5({
              data: string
          },callback);
        }

</script>
</html>
